package com.demo.demo.jinhua;

/**
 * Copyright
 *
 * @Author WuHuang
 * @Date 2022/7/8
 */

/**
 * 炸金花规则服务
 * @author lzq31
 *
 */
public class FgfGameRuleService implements CardGameRuleService {

    // 定义一个单态的服务对象
    private static FgfGameRuleService instance = new FgfGameRuleService();

    private FgfGameRuleService(){}

    public static FgfGameRuleService getInstance() {
        return instance;
    }


    @Override
    public int rule(CardHand cardHand1, CardHand cardHand2) {
        FgfCardHand fgf1 = (FgfCardHand) cardHand1;
        FgfCardHand fgf2 = (FgfCardHand) cardHand2;

// 首先判断牌型
        if (fgf1.getCardsType() > fgf2.getCardsType()) return 1;
        if (fgf1.getCardsType() < fgf2.getCardsType()) return -1;

// 如果牌型相同

// 比较豹子牌：只要看任意一张牌的点数就可以
        if (fgf1.getCardsType() == FgfCardHand.HAND_TYPE_VALUE_BZP) {
            if (fgf1.getPoker1().getPointValue() > fgf2.getPoker1().getPointValue()) return 1;
            if (fgf1.getPoker1().getPointValue() < fgf2.getPoker1().getPointValue()) return -1;
        }

// 比较顺金牌：比较最大的那种牌的点数
        if (fgf1.getCardsType() == FgfCardHand.HAND_TYPE_VALUE_SJP) {
            if (fgf1.getPoker3().getPointValue() > fgf2.getPoker3().getPointValue()) return 1;
            if (fgf1.getPoker3().getPointValue() < fgf2.getPoker3().getPointValue()) return -1;
        }

// 比较乱金牌：从3-1分别比较
        if (fgf1.getCardsType() == FgfCardHand.HAND_TYPE_VALUE_LJP) {
            if (fgf1.getPoker3().getPointValue() > fgf2.getPoker3().getPointValue()) return 1;
            if (fgf1.getPoker3().getPointValue() < fgf2.getPoker3().getPointValue()) return -1;

            if (fgf1.getPoker2().getPointValue() > fgf2.getPoker2().getPointValue()) return 1;
            if (fgf1.getPoker2().getPointValue() < fgf2.getPoker2().getPointValue()) return -1;

            if (fgf1.getPoker1().getPointValue() > fgf2.getPoker1().getPointValue()) return 1;
            if (fgf1.getPoker1().getPointValue() < fgf2.getPoker1().getPointValue()) return -1;
        }

// 比较乱顺牌：比较最大的那种牌的点数
        if (fgf1.getCardsType() == FgfCardHand.HAND_TYPE_VALUE_LSP) {
            if (fgf1.getPoker3().getPointValue() > fgf2.getPoker3().getPointValue()) return 1;
            if (fgf1.getPoker3().getPointValue() < fgf2.getPoker3().getPointValue()) return -1;
        }

// 比较对子牌：获得对子的牌点，然后如果对子牌点一样，要比较单张牌点
        if (fgf1.getCardsType() == FgfCardHand.HAND_TYPE_VALUE_DZP) {
            if (fgf1.getPoker2().getPointValue() > fgf2.getPoker2().getPointValue()) return 1;
            if (fgf1.getPoker2().getPointValue() < fgf2.getPoker2().getPointValue()) return -1;
            int fgf1Dp = 0;
            int fgf2Dp = 0;

            if (fgf1.getPoker1().getPointValue() == fgf1.getPoker2().getPointValue()) {
                fgf1Dp = fgf1.getPoker3().getPointValue();
            } else {
                fgf1Dp = fgf1.getPoker1().getPointValue();
            }

            if (fgf2.getPoker1().getPointValue() == fgf2.getPoker2().getPointValue()) {
                fgf2Dp = fgf2.getPoker3().getPointValue();
            } else {
                fgf2Dp = fgf2.getPoker1().getPointValue();
            }

            if (fgf1Dp > fgf2Dp) return 1;
            if (fgf1Dp < fgf2Dp) return -1;
        }

// 比较单顺牌：从3-1分别比较
        if (fgf1.getCardsType() == FgfCardHand.HAND_TYPE_VALUE_DSP) {
            if (fgf1.getPoker3().getPointValue() > fgf2.getPoker3().getPointValue()) return 1;
            if (fgf1.getPoker3().getPointValue() < fgf2.getPoker3().getPointValue()) return -1;

            if (fgf1.getPoker2().getPointValue() > fgf2.getPoker2().getPointValue()) return 1;
            if (fgf1.getPoker2().getPointValue() < fgf2.getPoker2().getPointValue()) return -1;

            if (fgf1.getPoker1().getPointValue() > fgf2.getPoker1().getPointValue()) return 1;
            if (fgf1.getPoker1().getPointValue() < fgf2.getPoker1().getPointValue()) return -1;
        }

        return 0;
    }


}

